$(function () {
    template.defaults.imports.formatDate = function (date) {
        date = new Date(date)
        var year = date.getFullYear()
        var month = date.getMonth() + 1
        var day = date.getDate()
        return year + '-' + month + '-' + day
    }

    function thelast() {
        $.ajax({
            type: 'get',
            url: 'admin/comments',
            success: function (res) {
                let val = template('last', res)
                $('.layui-table tbody').html(val)
            }
        })
    }
    thelast()
    $('.layui-table tbody').on('click', '.data', function (e) {
        let data = $(e.target).data('id')
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'DELETE',
                url: 'admin/comments/' + data,
                success: function (res) {
                    if (res.status === 0) {
                        layer.close(index)
                        thelast();
                    }
                }
            })
        })
    })
})